import Qt 4.7
import "content"
import "content/game.js" as Logic

Rectangle {
    id: game
    //VASCO CONFIG

    width: 480
    height: 320
    property int cols: 9
    property int rows: 5
    property int cell_size: 51;
    /*
    //PC CONFIG

    width: 1000
    height: 810
    property int cols: 25
    property int rows: 19
    property int cell_size: 39;
*/
    color: "#123"


    Column {
        anchors.centerIn: parent;
        spacing: 2;

        Row {
            spacing: 14;

            Button {
                id: btn_menu;
                width: board.width-difficulty.width-meter.width-28-14-36+2;
                height:36;
                text: "Restart"
                property int times_pressed: 1
                scale: 1;
                rotation: 0;
                onClicked: {
                    Logic.restart(times_pressed/2);
                    gameover.running = Logic.refreshConnections();
                    times_pressed++;
                    times_pressed = times_pressed%3;
                    // menu.state = "On";

                }
                SequentialAnimation {
                    id: gameover;
                    loops: Animation.Infinite;
                    alwaysRunToEnd: true;
                    running: false
                    NumberAnimation { target: btn_menu; property: "rotation"; to: 10; duration: 100 }
                    NumberAnimation { target: btn_menu; property: "rotation"; to: -10; duration: 100 }
                    NumberAnimation { target: btn_menu; property: "rotation"; to: 8; duration: 100 }
                    NumberAnimation { target: btn_menu; property: "rotation"; to: -6; duration: 100 }
                    NumberAnimation { target: btn_menu; property: "rotation"; to: 3; duration: 100 }
                    NumberAnimation { target: btn_menu; property: "rotation"; to: 0.0; duration: 100 }
                    NumberAnimation { target: btn_menu; property: "rotation"; to: 0.0; duration: 1000 }
                }
            }


            Text {
                id: difficulty
                width: 54;
                height:36;
                font.pixelSize:16;
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                color: "#fff"
                text: "Normal"
            }


            Meter {
                id: meter;
                digits: 5
                digit_h: 34
                digit_w: 28
                value: 0
            }
            Button {
                id: btn_quit;
                width: 36;
                height:36;
                color:"#caa"
                text: "X"
                onClicked: {
                    Qt.quit();

                }
            }
        }
        Text {

            anchors.horizontalCenter: parent.horizontalCenter;
            font.pixelSize:9;
            color: "#aaa"
            text: "Connect all houses with power station to win the game by Anton Teryaev :)"
        }
        Rectangle {
            width:board.width+2;
            height:board.height+2;
            color:"#bbb"


        Grid {
            id: board;
            x:1;y:1;
            columns: cols
            spacing: 1;
            Repeater {
                model: cols*rows
                GameCell {
                    width: cell_size-1
                    height:cell_size-1
                    onRotated: {
                        meter.value+=1;
                        gameover.running = Logic.refreshConnections();
                    }
                }
            }
        }//grid

        }



    }

    Component.onCompleted: {
        Logic.restart(0);
        gameover.running = Logic.refreshConnections();
    }
}
